package com.mmall.admin.shiro;

import com.mmall.common.util.SpringUtil;
import org.springframework.core.env.Environment;

import java.io.Serializable;

/**
 * 在dev 环境上 免token 登陆
 * @author gg
 * @version DevTool.java, v 0.1 2019-05-21 9:36 gg
 */
public class DevTool {

    private static final String DEV = "dev";

    private static final String ACTIVE = "spring.profiles.active";

    public static Serializable getDevSessionKey(Serializable id) {
        Environment env = SpringUtil.getBean(Environment.class);
        if (DEV.equals(env.getProperty(ACTIVE))) {
            id = DevTool.DEV;
        }
        return id;
    }


    public static ShiroUser getCurrentAdmin(ShiroUser shiroUser) {
        //这里需要在数据库存放一个名字叫dev的用户
        Environment env = SpringUtil.getBean(Environment.class);
        if (DEV.equals(env.getProperty(ACTIVE))) {
            ShiroUser cacheUser = new ShiroUser();
            cacheUser.setRoleIds("1");
            cacheUser.setUsername(DEV);
            return cacheUser;
        }
        return shiroUser;
    }


}